package com.honey.mybatis.generator.model.method;

import com.honey.compilation.java.IfBlock;
import com.honey.compilation.java.JavaKeyWord;
import com.honey.compilation.java.Method;
import com.honey.compilation.java.Parameter;
import com.honey.core.types.FullyQualifiedJavaType;
import com.honey.core.types.JDKFullyQualifiedJavaType;
import com.honey.mybatis.generator.AbstractMethod;
import com.honey.mybatis.generator.model.ModelConstant;

public class GetValueMethod extends AbstractMethod {
	
	private static final  String VARIABLE_CS="cs";
	
	private static final  String VARIABLE_INDEX="index";
	
	private static final Parameter []PARAMETER =new Parameter[]{ 
		
		new Parameter(ModelConstant.CALLABLE_STATEMENT,VARIABLE_CS),
		
		new Parameter(JDKFullyQualifiedJavaType.getIntInstance(),VARIABLE_INDEX),
	};
	
	private static final FullyQualifiedJavaType  RETURN_TYPE = JDKFullyQualifiedJavaType.getObjectInstance(); 
			
	
	private static final String[] JAVA_DOC=new String[]{
		"myBatis用户定义的类型转换，从CallableStatement中获取用户定义的对象。"
	};
	
	private static final String[] ANNOTATION = new String[]{
		"Override",
	};
	
	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#addBody(com.honey.compilation.java.Method)
	 */
	@Override
	protected void addBody(Method method) {
		IfBlock block = new IfBlock(VARIABLE_CS + ".wasNull()");
		block.addBodyLine(JavaKeyWord.RETURN.toString() + JavaKeyWord.NULL.getValue());
		method.addBlocks(block);
		method.addBodyLine(JavaKeyWord.RETURN+VARIABLE_CS+".getObject( "+VARIABLE_INDEX+" )");
	}
	
	/*
	 * (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getMethodName()
	 */
	@Override
	protected String getMethodName() {

		return ModelConstant.GET_RESULT_METHOD;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getParameter()
	 */
	@Override
	protected Parameter[] getParameter() {
		return PARAMETER;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getJavaDoc()
	 */
	@Override
	protected String[] getJavaDoc() {
		return JAVA_DOC;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getAnnotation()
	 */
	@Override
	protected String[] getAnnotation() {
		return ANNOTATION;
	}

	/* (non-Javadoc)
	 * @see com.honey.mybatis.generator.AbstractMethod#getReturnType()
	 */
	@Override
	protected FullyQualifiedJavaType getReturnType() {
		return RETURN_TYPE;
	}
	
	public static void main(String []args){
		GetValueMethod gr =new GetValueMethod ();
		System.out.println(gr.createMethod().compiledContent(1) );
	}
}
